
#ifndef GLOBALS_H
#define GLOBALS_H
#define u8 unsigned char
#define u16 unsigned short
#define u32 unsigned long
#define GetX(lParam) LOWORD(lParam)
#define GetY(lParam) HIWORD(lParam)
#include <windows.h>
#include "resource.h"
#include "image.h"
#include "Door Connections.h"
#include "sChecks.h"
#include "sCombo.h"
#include "Structures.h"
#include "GBAMethods.h"
#include "GameStructures.h"
#include "nRoomBuff.h"
#include "backbuffer.h"
#include "cStatEd.h"
#include "cSSE.h"
#include "cOamEdit.h"
#include "cClipboard.h"
#include "wndBGImport.h"
#include "clsScroll.h"
#include "Engine.h"
#ifndef EXT
#define EXT extern
#endif
//EXT int  GameEngine->isZM();//Current ROM file
EXT HWND  hwndTileset;
EXT HWND  InputHwnd;
int  ClearGlobals();
EXT HWND ExtendedOptWND;
int LoadExtensions();
int LoadCurSprite();
BOOL CALLBACK ExtendedProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
//EXT u8 Table[0xFF][0xFF][256];
LRESULT CALLBACK MiniTilesetProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK MiniProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK MiniGraphicProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK SprProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
EXT HINSTANCE hTileset;
EXT WNDCLASSEX wcTileset;
EXT HWND  hwndMap;
EXT HINSTANCE hMap;
EXT WNDCLASSEX wcMap;
EXT HINSTANCE hGlobal;
EXT RECT  TilesetRect;

EXT HWND hwndResize;
EXT HWND wndHE;
EXT u16 MFSprSize[0x180];
EXT HWND hPal;
int InitSceneryWindow();
//For scenery editor
EXT HWND SceneWnd;

int EditScrollData();
EXT HWND SceneGraph;
EXT HWND TSScene;
EXT HWND hwndMM;
int LoadSprArrays();
int GetBitField( long reg , long bitStart, long bitLength);
int DecodeOAM();
int DrawVRAMBuffer();
int CreateVRAMWindow();

#define Square		0
#define Horizontal  1
#define Vertical	2


EXT u32 SpriteOAM[0xff];
LRESULT CALLBACK SWProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
int InitTSWindow();
LRESULT CALLBACK TSWProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

int DrawGraphicTiles();
int InitPosArray();
int DecodeOAM();


EXT Image       SceneryPic;
EXT Image       SceneryTiles;
int DrawOAM(u8 cursprite);
int DrawThisScene(u8 Scene);
int LoadInput();

int ShowSprites(u8 Number);
int LoadZMROM();
int LoadMFROM();
int EnableConnections();
int DoesaBridgeExist();
int SetConnections(u8 conn);
int LoadData();
int SaveSprites();
EXT Drc         DoorConnections;
EXT int			nHScroll[32];
EXT int			nVScroll[32];
EXT int			nDisplayWidth[32];
EXT int			nDisplayHeight[32];
EXT int			nMaxHScroll[32];
EXT int			nMaxVScroll[32];
//EXT u8          fGbuf[0x8000];
//EXT long        PcPalMem[0x200];
EXT sChecks     CheckBoxes[32];
//EXT u8          BGBuf[0x8000];
//EXT tTSA        TSA;
//EXT gTileData   RoomTilesets[0x50];
//EXT gTileData   RoomTilesets[0x80];
EXT sCombo      Combos[80];
EXT Image		img[2];
EXT int			bRunApp;
EXT int         CurDoor;

//EXT long        DoorOffsets[10];
EXT long        scrollpnt;
EXT HWND        hwndHeader;
int ConnControls(bool How);
int DrawScrolls(int ScrollToDraw);
int SaveScroll();
int InitSpriteWindows();
int GetBG();
int DrawBackGround();
int SetupHeaderControls();

BOOL CALLBACK   SceneProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK ScrollProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK TSAProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
EXT Scroller scroll;
int GetScroll();
int initScroll();
//int MoveObj(u8 ObjNum, u8 Where);


EXT long RoomScrollOffset;
int SetupDoors();
int LoadDoors();
int DisplayDoors();
EXT HWND Main;
EXT GBAMethods GBA;
int MFGetGlobalTiles();
EXT SE SpecialEffects[16];
BOOL CALLBACK  TextEditorProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
EXT TileBuffer		TileImage;
EXT TileBuffer      BGImage;
EXT TileBuffer      SpriteImage;
//EXT RHeader         RoomHeader;
int LoadHeaderControls();
int ChangeSprites();
EXT char procstring[1024];
EXT long RoomOffsets[8];
EXT long        DoorOffsets[10];
//EXT long MFRoomOffsets[10];
EXT nRoomBuff* ThisLevelData;
EXT nRoomBuff* ThisBackLayer;
EXT nRoomBuff* ThisForeground;
EXT nRoomBuff* ThisClipData;
EXT nRoomBuff* ThisBackground;
EXT nRoomBuff* ThisRoomBuff;
EXT u8 CurMapWidth, CurMapHeight;
EXT LONG oldEditProc;
EXT short Tile;
EXT char AppPath[1024];
int SaveHeader(u8 call);
EXT nEnemyList Enemy1;
EXT nEnemyList Enemy2;
EXT nEnemyList Enemy3;
EXT u8 LoadingLevel;
EXT short GBASprPal[0x500];
int InitPalWindow();
LRESULT CALLBACK PalProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK TSAProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
EXT sDoor Doors[0xFF];
EXT u16    DoorNum;
EXT DoorStruct  DoorBuf;
EXT HWND DoorWin;
EXT HWND hScroll[40];

EXT int CurObjT;
EXT int CurObjNo;
EXT u8 ConnectExists;
EXT u8 PSCE[0x101];

EXT int MovingSprite[2];//0 is moving
                        //1 is the sprite
EXT int MovingDoor[2];//0 is moving
                        //1 is the sprite
EXT int MovingScroll[2];//0 is moving
                        //1 is the sprite
BOOL CALLBACK  SSProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
#define vSS 31
EXT int SFSS;
EXT int dispic;
EXT HWND hwndSS;
int SaveConnections();
int GetArrays();
int GetTileset(u8 Tileset);
int sMessage(char* messagestring);
int LoadSpecialEffects(long EffectNum);
int ZMGlobalGFX(u8 Area);
int MFGlobalGFX();
int LoadHeader(long Offset);
int GetLevelLayer();
//int InitScrolls();
EXT BackBuffer ThisBackBuffer;
void * resize(void * array, int varsize, int x, int y);
int DrawLevel();
int GetBackLayer();
int DrawRoom();
int GetForeLayer();
int DrawBlock(short Map16n , int destX , int destY);
void DrawTileset();
int InitTileset();
int InitMap();
EXT MousePointer mpTileset; 
EXT MousePointer mpMap; 
EXT MousePointer mpScene; 
EXT MousePointer mpSTS;
int SaveLevel(FILE* fp, u32 HeaderOffset);
int GetClipdata();
int DrawCtl(u8 Control);
int SaveThisDoor(int DoorNo);
int ConnectDoor(u8 TD);
BOOL CALLBACK  HeaderProced(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
EXT int curDoor;
LRESULT CALLBACK TilesetProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK MapProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK TSProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK DoorProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
//Combobox Defines each for a combo
EXT int DM[3];
EXT int TP[3];
EXT int MP[3];
EXT u8 compare;
EXT GFXData gfxpnt_dst[16];  //0 = pointer to gfx, 1 = destination in VRAM
EXT PalData paltransfer[16]; //0 = pointer to pal, 1 = destination, 2 = WORD count (*2 for bytes)
#define  sprgfxpnt  0x75EBF8 //comped sprite gfx pointer list
#define  sprpalpnt  0x75EEF0 //comped sprite pal pointer list
EXT  CompHeader thiscompheader;
EXT sprite_entry sprite_in[32];
EXT u8 maxsprite;
LRESULT CALLBACK InputBoxProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
int LoadInput();
int DrawClipIdent();
#define cArea    0 
#define cTileset 1
#define cRoom    2
#define cClip    3 
#define dType    4 
#define dConn    5 
#define dOwner   6
#define cConnect 7
#define cA1      8
#define cD1      9
#define cdA1     10
#define cA2      11
#define cD2      12
#define cdA2     13
#define cSpriteSet 14
//Image Defines
#define iTileset 0
#define iRoom 1
//Scroll Bar Defines
#define sTileset 0
#define sHMap 1
#define sVMap 2
#define sWidth 3
#define sHeight 4
#define sHRoom 5
#define hsbC1v 1
#define hsbC2v 2
#define hsbC3v 3
//blah

//Checkboxes
#define Foreground 0
#define Level 1
#define Background 2
#define Clip 3
#define ViewF 4
#define ViewL 5
#define ViewB 6
#define sMove 7
#define sResize 8
#define sView 9 
#define ZM 0
#define MF 1
#define use 0
#define doorn 1
#define SBG 20
#define SP 21
#define viewBG 10
#define chkES  99
#define chkED  100
#define chkESC 101
//For DrawIt

#define showmap 18
#define showtileset 19

#define SceneVScroll 12
#define SceneHScroll 13
#define STVScroll  14
#define dDoor 0
#define dScroll 1
#define dSprite 2
#define ValType 0
#define StrType 1 
EXT int InputType;
EXT int SceneTile;
EXT u8  SceneType;
EXT sChecks ScrollCheck;
EXT sChecks ViewClip;
int Findmeascroll(int X,int Y);
EXT cStatEd StatEditor;
BOOL CALLBACK  SEProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
EXT sSpritev VRAM;
void ChangeCompression(u8 oldlayervalue, u8 newval, u8 layer, nRoomBuff* buffer);
EXT cSSE SpriteSet;
EXT bool SSE;
EXT bool SSE2;
int LoadInput(long val);
int SavePal(PalData* palinfo,sprite_entry* spriteset, long *Palette);
int DrawSSprite( SprGBuf* SpriteDetails);
LRESULT CALLBACK SSESpriteProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK SSEPalProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK  SSEProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void setsize(nRoomBuff* buffer);
void ChangeCompression(u8 oldlayervalue, u8 newval, u8 layer, nRoomBuff* buffer);
int CCLevel();
int SaveCurScene();
int WriteDataToROM(u8* datastream, u32 size,u32 offset);
int DrawLayer(nRoomBuff* Map, u8 ctype);
BOOL CALLBACK	      OAMProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK    OAMPalProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK   OAMTileProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK OAMSpriteProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void DrawPal(HDC hdc,long* palette);
EXT cOAMEdit OamEditor;
EXT bool 	OAMED;

EXT BackBuffer BBTileset;
BOOL CALLBACK	    ClipBoardProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK    CBImageProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
EXT cClipboard  ClipBoard;
EXT u8  MPToUse;
int SetTiles(LPARAM lParam);
EXT sChecks chkDoTrans;
int ExportPal();
int ImportPal();
int ExportGFX();
int ImportGFX();
int SavePal();
int SaveGFX();
EXT sChecks   chkMC[4];

int GetZMSetSZ  (long* GFXSizes,long*PalSizes, sprite_entry* SpriteInfo);

int GetMFSetSZ  (long* GFXSizes,long*PalSizes, sprite_entry* SpriteInfo);

int CheckTheSize(sprite_entry* SE);
EXT u8 DefRoom;
EXT u8 DefArea;
EXT u32 DefAddress;
int LoadConfigFile(char* ConfigLoc);
int ExportRoom();
int ImportRoom();
int StrToFile(char *str, FILE* fp);
int HandleRightClick(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
EXT HWND hConn; 
unsigned short cprs_gba_lz77(RECORD *dst, const RECORD *src);
EXT int  drawmm; 
EXT sCombo LayerCombo;
EXT int  ScP[2];
EXT int  SmP[2];
EXT int  SCS; //Scenery Copy Source
EXT wndBGImport  BGi;
BOOL CALLBACK BGiProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
EXT u8   import;
int GetCBG();
int ApplyIPS(char* ipsfile, char* dstfile);
EXT int BGiInstall;
int GetLayerData(Engine* mEngine,u8 compression, u8 Layer, u32 offset);
BOOL CALLBACK LPProc (HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
EXT HWND hwndLPE;
EXT int  palscroll[3];
int DrawPal(HDC hdc,long* palette,int X, int Y, int palcol);
EXT u8 clrIndex;
EXT clsScroll scrMapV;
EXT clsScroll scrMapH;
EXT clsScroll scrTSV;
EXT clsScroll scrColors[3];
EXT int       curclr;
int LoadColor(long Pal);
int ChangeColor();
int Export(char* FilePath);

int Import(char* FilePath);
EXT sCombo cboScroll;
EXT BackBuffer  BB;
EXT sCombo cboTSAPAL;

EXT HWND hwndInsert; 
BOOL CALLBACK  InsertProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
int LoadTrans(char* Directive, int DataType,HWND hwnd);
void TransMenu(char* MenuName,FILE* fp,HWND hwnd);
u16 ApplyMenuString(int tMenu,char* string,HWND hwnd, u16 Counter );
EXT Engine* GameEngine;
#endif